package com.kfm.jdbc.day0406;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class UDPReceiver {

    public static void main(String[] args) {

        try {
            InetAddress local = InetAddress.getLocalHost();
            System.out.println(local);
            DatagramSocket datagramSocket = new DatagramSocket(8888, local);
            byte[] bytes = new byte[1024];
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length);

            while (true){
                datagramSocket.receive(packet);

                String s = new String(packet.getData(), 0, packet.getLength());
                System.out.println(s);
            }



        } catch (SocketException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}


